<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>fseek</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_005_284">&nbsp;</a>NAME</h4><blockquote>
fseek, fseeko - reposition a file-position indicator in a stream
</blockquote><h4><a name = "tag_000_005_285">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="stdio.h.html">stdio.h</a>&gt;

int fseek(FILE *<i>stream</i>, long int <i>offset</i>, int <i>whence</i>);
int fseeko(FILE *<i>stream</i>, off_t <i>offset</i>, int <i>whence</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_005_286">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>fseek()</i>
function sets the file-position indicator for the stream pointed to by
<i>stream</i>.
<p>
The new position, measured in bytes from the beginning of the file, is
obtained by adding
<i>offset</i>
to the position specified by
<i>whence</i>.
The specified point is the beginning of the file for SEEK_SET, the
current value of the file-position indicator for SEEK_CUR, or
end-of-file for SEEK_END.
<p>
If the stream is to be used with wide-character input/output functions,
<i>offset</i> must either be 0 or a value returned by an earlier call to
<i><a href="ftell.html">ftell()</a></i>
on the same stream and <i>whence</i> must be SEEK_SET.
<p>
A successful call to
<i>fseek()</i>
clears the end-of-file indicator for the stream and undoes any effects of
<i><a href="ungetc.html">ungetc()</a></i>
and
<i><a href="ungetwc.html">ungetwc()</a></i>
on the same stream.  After an
<i>fseek()</i>
call, the next operation on an update stream may be either input or output.
<p>
If the most recent operation, other than
<i><a href="ftell.html">ftell()</a></i>,
on a given stream is
<i><a href="fflush.html">fflush()</a></i>,
the file offset in the underlying open file description will
be adjusted to reflect the location specified by
<i>fseek()</i>.
<p>
The
<i>fseek()</i>
function allows the file-position indicator to be set
beyond the end of existing data in the file.
If data is later written
at this point, subsequent reads of data in the gap will return bytes
with the value 0 until data is actually written into the gap.
<p>
The behaviour of
<i>fseek()</i>
on devices which are incapable of seeking is implementation-dependent.
The value of the file offset associated with such a device is undefined.
<p>
If the stream is writable and buffered data had not been written to the
underlying file,
<i>fseek()</i>
will cause the unwritten data to be written to
the file and mark the
<i>st_ctime</i>
and
<i>st_mtime</i>
fields of the file for update.
<p>
In a locale with state-dependent encoding, whether
<i>fseek()</i>
restores the stream's shift state is implementation-dependent.
<p>
The 
<i>fseeko()</i>
function is identical to the 
<i>fseek()</i>
function except that the 
<i>offset</i>
argument is of type 
<b>off_t</b>.
</blockquote><h4><a name = "tag_000_005_287">&nbsp;</a>RETURN VALUE</h4><blockquote>
The
<i>fseek()</i>
and
<i>fseeko()</i>
functions return 0 if they succeed; otherwise they return
-1
and set
<i>errno</i>
to indicate the error.
</blockquote><h4><a name = "tag_000_005_288">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>fseek()</i>
and
<i>fseeko()</i>
functions will fail if, either the
<i>stream</i>
is unbuffered or the
<i>stream</i>s
buffer needed to be flushed, and the call to
<i>fseek()</i>
or
<i>fseeko()</i>
causes an underlying
<i><a href="lseek.html">lseek()</a></i>
or
<i><a href="write.html">write()</a></i>
to be invoked:
<dl compact>

<dt>[EAGAIN]<dd>
The O_NONBLOCK flag is set for the file descriptor and the process
would be delayed in the write operation.

<dt>[EBADF]<dd>
The file descriptor underlying the stream file is not open for writing or
the stream's buffer needed to be flushed and the file is not open.


<dt>[EFBIG]<dd>
An attempt was made to write a file that exceeds
the maximum file size
&nbsp;or the process' file size limit.

<dt>[EFBIG]<dd>
The file is a regular file and an attempt was made to write at or beyond
the offset maximum associated with the corresponding stream.

<dt>[EINTR]<dd>
The write operation was terminated due to the receipt of a signal,
and no data was transferred.

<dt>[EINVAL]<dd>
The
<i>whence</i>
argument is invalid.
The resulting file-position indicator would be set to a negative value.

<dt>[EIO]<dd>
A physical I/O error has occurred, or
&nbsp;the process is a member
of a background process group attempting to perform a
<i><a href="write.html">write()</a></i>
to its
controlling terminal, TOSTOP is set, the process is neither ignoring nor
blocking SIGTTOU and the process group of the process is
orphaned.
This error may also be returned under implementation-dependent conditions.

<dt>[ENOSPC]<dd>
There was no free space remaining on the device containing the file.

<dt>[EOVERFLOW]<dd>
For
<i>fseek()</i>,
the resulting file offset would be a value which cannot be represented
correctly in an object of type 
<b>long</b>.

<dt>[EOVERFLOW]<dd>
For
<i>fseeko()</i>,
the resulting file offset would be a value which cannot be represented
correctly in an object of type 
<b>off_t</b>.

<dt>[EPIPE]<dd>
The file descriptor underlying
<i>stream</i>
is associated with a pipe or FIFO.

<dt>[EPIPE]<dd>
An attempt was made to write to a pipe or FIFO that
is not open for reading by any process; a SIGPIPE
signal will also be sent to the thread.

<dt>[ENXIO]<dd>
A request was made of a non-existent device, or the request was
outside the capabilities of the device.

</dl>
</blockquote><h4><a name = "tag_000_005_289">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_290">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_291">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_005_292">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="fopen.html">fopen()</a></i>,
<i><a href="fsetpos.html">fsetpos()</a></i>,
<i><a href="ftell.html">ftell()</a></i>,
<i><a href="getrlimit.html">getrlimit()</a></i>,
<i><a href="rewind.html">rewind()</a></i>,
<i><a href="ulimit.html">ulimit()</a></i>,
<i><a href="ungetc.html">ungetc()</a></i>,
<i><a href="stdio.h.html">&lt;stdio.h&gt;</a></i>.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from Issue 1 of the SVID.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

